﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;

namespace comm_num_tp1
{
    public class GpRMC : GpsSubCommon
    {
        /*
        $GPRMC,225446,A,4916.45,N,12311.12,W,000.5,054.7,191194,020.3,E,68
        
        225446 = Heure du Fix 22:54:46 UTC
        A = Alerte du logigiel de navigation ( A = OK, V = warning (alerte)
        4916.45,N = Latitude 49 deg. 16.45 min North
        12311.12,W = Longitude 123 deg. 11.12 min West
        000.5 = vitesse sol, Knots
        054.7 = cap (vrai)
        191194 = Date du fix 19 Novembre 1994
        020.3,E = Déclinaison Magnetique 20.3 deg Est
        68 = checksum obligatoire
        */
        private DateTime _rmcDate;

        #region constructor
        public GpRMC(string Iden, string Time, string Warning, string Lat, string Lon, string Speed, string Bearing, string Date, string DeclMagnetDeg, string chksum)
        {
            StreamIden = Iden;
            StreamTime = Time;
            StreamWarning = Warning;
            StreamSpeed = Speed;
            StreamBearing = Bearing;
            StreamDeclMagnetDeg = DeclMagnetDeg;
            StreamLon = Lon;
            StreamLat = Lat;
            StreamDate = Date;
            StreamChecksum = chksum;
            IsGsvList = false;
        }
        #endregion

        #region accessors
        public string StreamRawStream { get; set; }
        public string StreamWarning { get; set; }
        public string StreamSpeed { get; set; }
        public string StreamBearing { get; set; }
        public string StreamDeclMagnetDeg { get; set; }
        public string StreamDate
        {
            get
            {
                string myDate = "";
                if (_rmcDate != null)
                    myDate = _rmcDate.ToString("ddMMyy");
                return myDate;
            }
            set
            {
                if (!String.IsNullOrEmpty(value))
                {
                    string preDate = value.Substring(0, 2) + "-" + value.Substring(2, 2) + "-" + value.Substring(4, 2);
                    _rmcDate = DateTime.ParseExact(preDate, "dd-MM-yy", CultureInfo.InvariantCulture);
                }
            }
        }
        #endregion

        public override string ToString()
        {
            string retour = "";
            retour = StreamIden + "," + StreamTime + ',' + StreamWarning + "," + StreamSpeed + "," + StreamBearing + "," + StreamDeclMagnetDeg + "," +
                StreamLon + "," + StreamLat + "," + StreamDate + ","  + StreamChecksum;
            return retour;
        }
    }
}
